package com.bwie.controller;

import com.bwie.pojo.Order;
import com.bwie.result.Result;
import com.bwie.service.OrderService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/order")
@RestController
@Log4j2
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/list")
    public Result<List<Order>> list(){
        try {
            List<Order> list=orderService.list();
            Result<List<Order>> result = Result.success(list);
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("/refund")
    public Result refund(@RequestBody Order order){
        orderService.refund(order);
        Result result = Result.success(order);
        return result;
    }

    @GetMapping("/findByOrderId/{id}")
    public Result<Order> findByOrderId(@PathVariable("id") Integer id){
        Order order=orderService.findByOrderId(id);
        Result<Order> result = Result.success(order);
        return result;
    }



}
